package org.fengling.readingplatform.manager.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.fengling.readingplatform.manager.service.CategoryService;
import org.fengling.readingplatform.model.entity.novel.Category;
import org.fengling.readingplatform.model.vo.common.Result;
import org.fengling.readingplatform.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "分类管理接口")
@RestController
@RequestMapping(value="/admin/novel/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //导入
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        //获取上传文件
        categoryService.importData(file);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //导出
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    //查询所有一级分类
    @GetMapping("/findFirstCategory")
    public Result<List<Category>> findFirstCategory(){
        List<Category> categoryList = categoryService.findFirstCategory();
        return Result.build(categoryList, ResultCodeEnum.SUCCESS);
    }

    //分类列表，每次查询一层数据
    @GetMapping("/findCategoryList/{id}")
    public Result findCategoryList(@PathVariable Long id){
        List<Category> list = categoryService.findCategoryList(id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
